<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>用户设置</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<%@include file="common.jsp"%>
</head>
<body>
	<div id="toolbar"></div>
	<div style="margin-top:-10px;">
		<table id="userTable" class="text-nowrap"></table>
	</div>
	
	<!-- 修改用户余额 -->
	<div class="modal fade" id="updateBalance" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">修改余额</h4>
            </div>
            <div class="modal-body">
           		 <form id="userForm" method='post' class="form-inline" enctype="multipart/form-data">
				 	<div class="form-group">
				    	<label for="exampleInputName2">用户帐号：</label>
				    	<input id="userName" name="userName" class="form-control"/>
				    	<input id="userCode" name="userCode" hidden="ture"/>
				  	</div>
				  	<div class="form-group" style="margin-left:20px;">
				    	<label for="exampleInputEmail2">用户余额：</label>
				    	<input id="userMoney" name="userMoney" type="number" class="form-control"/>
				  	</div>
				</form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" id="updateUserInfo" onclick="updateBalance()">修改</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
	</div>
</body>
<script type="text/javascript">
//重载表格
$(function(){
	//加载表格
	$("#userTable").bootstrapTable({
		url: "${pageContext.request.contextPath}/user/findUser.do",
		method: "post",
		cache: false,
		dataType: "json",
		contentType: "application/x-www-form-urlencoded",
		toolbar: "#toolbar",
		classes: "table table-hover table-striped",
		height:520,
		pagination: true,
		sidePagination: 'server',
		search: false,
		smartDisplay:false,
		sortOrder: "desc",
		searchText: "",
		showRefresh: false,
		showToggle: false,
		singleSelect: true,
		showPaginationSwitch: false,
		pageNumber: 1,
		pageSize: 5,
		pageList: [5, 10, 20, 40],
		clickToSelect: true,
		onCheck: function (row) {
		},
		queryParamsType: "undefined",
		queryParams: function (params) {
			var params = {
				pageNum: params.pageNumber,
				pageSize: params.pageSize,
				sortBy: params.sortOrder,
			}
			return params;
		},
		columns: [
			{
				field: "userCode",
				title: "用户编码"
			}, {
				field: "userName",
				title: "用户名称"
			}, {
				field: "userTypeCodeName",
				title: "用户类别"
			}, {
				field: "userOpenid",
				title: "用户唯一标识"
			}, {
				field: "balance",
				title: "余额"
			},{
				field: "phoneNum",
				title: "电话号码"
			}, {
				field: "userSuperiorCodeName",
				title: "上级用户"
			}, {
				field: "userSuperiorCodeNameTwo",
				title: "上上级用户"
			}, {
				field: "userSuperiorCodeNameThree",
				title: "上上上级用户"
			}, {
				field: "createTime",
				title: "创建时间",
				formatter: formatTime
			}
			
		],
		responseHandler: function (data) {//onLoad前处理数据源
			return data;
		},
		onLoadSuccess: function (data) {	//成功时执行
		},
		onLoadError: function (data) {	//失败时执行
			return;
		},
		//双击行事件
		onDblClickRow:function(row){
			//控件赋值
			$('#userName').val(row.userName);
			$('#userCode').val(row.userCode);
			$('#userMoney').val(row.balance);
			//打开弹出框
			$('#updateBalance').modal('show');
		}
	});
	//重载表格
	$(window).resize(function () {
		$('#table').bootstrapTable('resetView');
	});
})

function updateBalance(){
	if(confirm("确认修改？")){
		var submitData = new FormData(document.getElementById("userForm"));
		$.ajax({
			url: "${pageContext.request.contextPath}/user/updateBalance.do",
			data: submitData,
			type: "post",
			processData: false,
			contentType:false,
			success:function(data){
				alert(data);
				//刷新表格数据
				$('#userTable').bootstrapTable('refresh');
				//隐藏模态框
				$('#updateBalance').modal('hide');
			}
		})
	}
}
</script>
</html>




